import { ElLoading } from 'element-plus'


class LoadingBox {
    /**
     * el-loading实例
     */
    _instance = null

    /**
     * 打开加载动画框
     * @param {Boolean} show 是否显示加载动画框
     * @returns {}
     */
    static open(show, text='请稍候') {
        const inst = new LoadingBox()
        if (show) {
            // eslint-disable-next-line no-undef
            inst._instance = ElLoading.service({ lock: true, text: text})
        }
        return inst
    }

    /**
     * 关闭加载动画框
     */
    close() {
        this._instance?.close()
    }
}

export default LoadingBox